package element;

import java.awt.Color;
import java.awt.Graphics2D;
import springiesSimulator.Assembly;
import util.Vector;


/**
 * @author Mark Govea and Mark Hoffman
 */
public class Bar extends Spring {
    private static final int BAR_K_VALUE = 10;

    /**
     * @param start the first mass attached to a spring
     * @param end the second (final) mass attached to a spring
     * @param length distance between the masses
     * @param kVal the spring constant in Hooke's law
     */
    public Bar (Mass start, Mass end, double length, double kVal) {
        super(start, end, 0, BAR_K_VALUE);
        setMyLength(getCurrentLength());
    }

    /**
     * @param pen for selecting which color to use
     */
    @Override
    public void setPaintColor (Graphics2D pen) {
        double len = getCurrentCompression();

        if (Math.abs(len) < REST_THRESHOLD) {
            pen.setColor(Color.GRAY);
        }
        else if (len > 0.0) {
            pen.setColor(Color.BLUE.darker());
        }
        else {
            pen.setColor(Color.RED.darker());
        }
    }
}
